package Exercise;

import java.util.ArrayList;

/**
 * @author 王艺锡
 * @version 1.0
 */
public class Exercise01 {
    @SuppressWarnings({"all"})
    public static void main(String[] args) {
        ArrayList arrayList = new ArrayList();
        arrayList.add(new News("震惊，一男子虎彪竟然做出这种事情。"));
        arrayList.add(new News("找寻怪兽玛格尼亚的弱电，欢迎收看下集，大雾来了!"));
        int sz = arrayList.size();
        for (int i = sz - 1;i >= 0;i--){
            //System.out.println(arrayList.get(i));
            News news = (News)arrayList.get(i);
            System.out.println(str(news.getTitle()));
        }
    }
    public static String str(String title){
        if(title == null){
            return " ";
        } else if(title.length() > 15){
            //substring截取字符串，下标[0,15)
            return title.substring(0, 15) + "...";
        }
        else{
            return title;
        }
    }
}
class News{
    private String title;
    private String content;

    public News(String title) {
        this.title = title;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    @Override
    public String toString() {
        return title;
    }
}
